package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.User_Inf;
import entity.User_level_inf;
import service.OyxUser_levelMessageService;
import service.OyxVipUsermessageService;
import service.impl.OyxUser_levelMessageServiceImpl;
import service.impl.OyxVipUsermessageServiceImpl;


public class OyxVipUserMessageServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");		
		OyxVipUsermessageService vum = new OyxVipUsermessageServiceImpl();
		OyxUser_levelMessageService ulms = new OyxUser_levelMessageServiceImpl();
		
		
		//得到当前登录用户对象
		User_Inf user_InfMessage = vum.getUser_InfMessage(8);
		System.out.println(user_InfMessage);
        //将当前用户对象存入request中 并转发到前端jsp页面
		request.setAttribute("user_InfMessage", user_InfMessage);
		Integer point = user_InfMessage.getUser_point();
		Integer consumeMoney = point*10;
		request.setAttribute("consumeMoney", consumeMoney);
		Integer user_level = user_InfMessage.getUser_level();
		//通过用户对象里的会员等级user_level 对应得出会员信息对象
		User_level_inf user_levelMessage = ulms.getUser_levelMessage(user_level);
		request.setAttribute("user_levelMessage", user_levelMessage);
		//会员积分最大值减去当前会员积分 得出距离下一级还差多少积分
		Integer max_point = user_levelMessage.getMax_point();
		Integer user_point = user_InfMessage.getUser_point();
		Integer differ_point=max_point-user_point;
		if (differ_point>5000) {
			differ_point = null;
			String userVipHint = "您已是尊贵的顶级会员！！！";
			request.setAttribute("userVipHint", userVipHint);
		}else {
			String userVipHint = "您还差"+differ_point+"积分达到 下一级";
			request.setAttribute("userVipHint", userVipHint);
		}
		System.out.println(differ_point);
		
		request.getRequestDispatcher("Member_User.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
